﻿using Microsoft.AspNetCore.Http;
using Swimj.Core.Securities;

namespace Swimj.AspNetCore.Infrastructure.Auth
{
    public class SecurityMiddleware : IMiddleware
    {
        private readonly ICurrentUserInitializer _currentUserInitializer;

        public SecurityMiddleware(ICurrentUserInitializer currentUserInitializer)
        {
            _currentUserInitializer = currentUserInitializer;
        }

        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            _currentUserInitializer.SetCurrentUser(context.User);
            await next(context);
        }
    }
}
